﻿using System.Collections.Generic;
using System.Linq;
using GuRenFang.Service.Entity;
using GuRenFang.Service.IDa;

namespace GuRenFang.Da
{
   public class PhotosRepository : RepositoryBase<Photos>, IPhotosRepository
    {
       public PhotosRepository(IDatabaseFactory databaseFactory)
            : base(databaseFactory)
         {

         }
        
       public IEnumerable<WeddingPhoto> GetWeddingPhotosByPages(int pageIndex, int pageSize, string orderFiled,out int totalRecord)
        {
            var startRecord = pageSize * (pageIndex- 1);
            totalRecord = DataContext.Photos.OfType<WeddingPhoto>().Count();
            return this.DataContext.Photos.OfType<WeddingPhoto>().OrderByDescending(n => n.Id).Skip(startRecord).Take(pageSize);

        }
       public IEnumerable<PictorialPhoto> GetPictorialPhotoByPages(int pageIndex, int pageSize, string orderFiled, out int totalRecord)
       {
           var startRecord = pageSize * (pageIndex - 1);
           totalRecord = DataContext.Photos.OfType<PictorialPhoto>().Count();
           return this.DataContext.Photos.OfType<PictorialPhoto>().OrderByDescending(n => n.Id).Skip(startRecord).Take(pageSize);

       }

       public IEnumerable<Photos> GetItemsByPagesForHomePage(int pageIndex, int pageSize)
       {
           return DataContext.Photos.Where(m => m.IsDisplayOnHomePage == true).OrderByDescending(m => m.Id).Skip((pageIndex-1)*pageSize).Take(pageSize);

       }
       public IEnumerable<Photos> GetItemsByPagesForHomePage(out int totalRecord,int pageIndex, int pageSize)
       {
           var startRecord = pageSize * (pageIndex - 1);
           totalRecord =DataContext.Photos.Count(m => m.IsDisplayOnHomePage == true);
           return DataContext.Photos.Where(m => m.IsDisplayOnHomePage == true).OrderByDescending(m => m.Id).Skip(startRecord).Take(pageSize);

       }
    }
}
